package site.param.util;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by Administrator on 2017/1/5.
 */
public class SessionFileter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        try {
            filterChain.doFilter(servletRequest,servletResponse);
            /*
            String userName = request.getSession().getAttribute("userName").toString();
            String passwd = request.getSession().getAttribute("passwd").toString();
            if (userName!=null&&passwd!=null){
                filterChain.doFilter(servletRequest,servletResponse);
            }else {
                servletResponse.getWriter().print("Session has been invalidated! ");
            }*/
        } catch (IOException |ServletException e) {
            //e.printStackTrace();
            servletResponse.getWriter().print("System error!");
        }

    }

    @Override
    public void destroy() {

    }
}
